home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / gc / GCutilities.c < prev    next >
C/C++ Source or Header  |  1991-06-06  |  4KB  |  190 lines

  1. /* begincopyright
  2.   Copyright (c) 1988,1990 Xerox Corporation. All rights reserved.
  3.   Use and copying of this software and preparation of derivative works based
  4.   upon this software are permitted. Any distribution of this software or
  5.   derivative works must comply with all applicable United States export
  6.   control laws. This software is made available AS IS, and Xerox Corporation
  7.   makes no warranty about the software, its performance or its conformity to
  8.   any specification. Any person obtaining a copy of this software is requested
  9.   to send their name and post office or electronic mail address to:
  10.     PCR Coordinator
  11.     Xerox PARC
  12.     3333 Coyote Hill Rd.
  13.     Palo Alto, CA 94304
  14.   endcopyright */
  15.  
  16. /*
  17.  * Weiser
  18.  *
  19.  * Demers, February 12, 1990 12:44:19 pm PST
  20.  * Boehm, March 26, 1990 12:51:22 pm PST
  21.  */
  22.  
  23. #include <xr/GCPrivate.h>
  24.  
  25.  
  26. unsigned
  27. XR_GCHeapSize()
  28. {
  29.   return GC_heapsize;
  30. }
  31.  
  32. unsigned
  33. XR_GCTotalObjectCount()
  34. {
  35.   return (GC_objects_allocd + GC_objects_allocd_before_gc);
  36. }
  37.  
  38. unsigned
  39. XR_GCCurrentObjectCount()
  40. {
  41.   return (GC_objects_in_use + GC_objects_allocd);
  42. }
  43.  
  44. unsigned
  45. XR_GCTotalByteCount()
  46. {
  47.   return WORDS_TO_BYTES(GC_words_allocd + GC_words_allocd_before_gc);
  48. }
  49.  
  50. unsigned
  51. XR_GCCurrentByteCount()
  52. {
  53.   return WORDS_TO_BYTES(GC_atomic_in_use + GC_composite_in_use
  54.               + GC_words_allocd);
  55. }
  56.  
  57. bool
  58. XR_GCSetNeverCollectAtAll(arg)
  59. {
  60.   bool old_value = GC_dont_gc;
  61.   GC_dont_gc = arg;
  62.   return old_value;
  63. }
  64.  
  65. XR_GCGetNeverCollectAtAll()
  66. {
  67.   return GC_dont_gc;
  68. }
  69.  
  70. bool
  71. XR_GCSetMarkCarefully(arg)
  72. {
  73.   bool old_value = GC_markCarefully;
  74.   GC_markCarefully = arg;
  75.   return old_value;
  76. }
  77.  
  78. unsigned
  79. XR_GCSetMode(arg)
  80. unsigned arg;
  81. {
  82.     unsigned old_value;
  83.     
  84.     if (arg == GC_PARALLEL) {
  85.         GC_iprintf("Currently PARALLEL ==> INCREMENTAL\n");
  86.         arg |= GC_INCREMENTAL;
  87.     }
  88. #   ifndef DIRTY_BITS
  89.       if (arg & DIRTY_BITS_REQUIRED) {
  90.           GC_iprintf("Parallel/incremental collection not possible\n");
  91.           arg &= ~DIRTY_BITS_REQUIRED;
  92.       }
  93. #   endif
  94.     GC_requested_mode = arg;
  95.     return(old_value);
  96. }
  97.  
  98. bool
  99. XR_GCGetMarkCarefully()
  100. {
  101.    return GC_markCarefully;
  102. }
  103.  
  104. void
  105. XR_RegisterGCCallBackBefore(before, clientdata, oldbefore, oldclientdata)
  106. RegisterGCCallbackType before;
  107. XR_Pointer clientdata;
  108. RegisterGCCallbackType *oldbefore;
  109. XR_Pointer *oldclientdata;
  110. {
  111.   XR_MonitorEntry(&GC_allocate_ml);
  112.   if (oldbefore) *oldbefore = GC_callBackBefore;
  113.   if (oldclientdata) *oldclientdata = GC_callBackBeforeClientData;
  114.   GC_callBackBefore = before;
  115.   GC_callBackBeforeClientData = clientdata;
  116.   XR_MonitorExit(&GC_allocate_ml);
  117. }
  118.  
  119. void
  120. XR_RegisterGCCallBackAfter(after, clientdata, oldafter, oldclientdata)
  121. RegisterGCCallbackType after;
  122. XR_Pointer clientdata;
  123. RegisterGCCallbackType *oldafter;
  124. XR_Pointer *oldclientdata;
  125. {
  126.   XR_MonitorEntry(&GC_allocate_ml);
  127.   if (oldafter) *oldafter = GC_callBackAfter;
  128.   if (oldclientdata) *oldclientdata = GC_callBackAfterClientData;
  129.   GC_callBackAfter = after;
  130.   GC_callBackAfterClientData = clientdata;
  131.   XR_MonitorExit(&GC_allocate_ml);
  132. }
  133.  
  134. void
  135. XR_RegisterGCCallBackDuringInner(during, clientdata, oldduring, oldclientdata)
  136. RegisterGCCallbackType during;
  137. XR_Pointer clientdata;
  138. RegisterGCCallbackType *oldduring;
  139. XR_Pointer *oldclientdata;
  140. {
  141.   if (oldduring) *oldduring = GC_callBackDuring;
  142.   if (oldclientdata) *oldclientdata = GC_callBackDuringClientData;
  143.   GC_callBackDuring = during;
  144.   GC_callBackDuringClientData = clientdata;
  145. }
  146.  
  147. unsigned
  148. XR_SetBytesAfterWhichToCollect(bytes)
  149. unsigned bytes;
  150. {
  151.     int oldValue;
  152.     
  153.     if (GC_mode != 0) {
  154.       oldValue = GC_partial_gc_allocs;
  155.       GC_partial_gc_allocs = GC_full_gc_allocs = bytes;
  156.     } else {
  157.       oldValue = GC_full_gc_allocs;
  158.       GC_full_gc_allocs = bytes;
  159.     }      
  160.     return oldValue;
  161. }
  162.  
  163. unsigned
  164. XR_GetBytesAfterWhichToCollect()
  165. {
  166.     if (GC_mode != 0) {
  167.       return GC_partial_gc_allocs;
  168.     } else {
  169.       return GC_full_gc_allocs;
  170.     }  
  171. }
  172.  
  173. void
  174. XR_CollectOnlyWhenFull()
  175. {
  176.     (void) XR_SetBytesAfterWhichToCollect(0);
  177. }
  178.  
  179. void
  180. XR_CollectAfterOneMegabyte()
  181. {
  182.     (void) XR_SetBytesAfterWhichToCollect(1024*1024);
  183. }
  184.  
  185. void
  186. XR_CollectAfterTwoMegabytes()
  187. {
  188.     (void) XR_SetBytesAfterWhichToCollect(1024*1024*2);
  189. }
  190.